<template>
	<div class="mui-content mgb2">
		<div class="mui-table-view">
			<div class="car-info flex-box mui-table-view-cell">
				<div class="car-brand-time flex-2" v-link="{name:'ucenterCar'}">
					<div class="car-logo mui-pull-left">
						<img :src="carBrandImage"/>
					</div>
					<div class="" v-if="carModel.length>0">
						<h4 class="car-brand1 font-normal">{{carModel}}</h4>
						<p class="car-buy-time">{{carBuyDate}}购入</p>
					</div>
				</div>
				<div class="car-mileage flex-1 tc">
					<h4 class="font-normal" @click="enterMileage()">{{carMileage}} km<i class="iconfont fr font-20 font-easy">&#xe63b;</i></h4>
					<p>行驶里程</p>
				</div>
			</div>
		</div>
		<div class="mui-table-view-cell mg-t-def clearfix bg-color-white">
			<div class="col-8">
				<p>已选保养项目<span class="mui-badge mui-badge-danger">{{itemNum}}</span></p>
			</div>
			<div class="col-4 mui-navigate-right font-14 select-more mui-text-right"><a href="javascript:;" @click="byItemSave()">选择更多项目</a></div>
		</div>
		<div class="mui-table-view-cell mg-t-def clearfix bg-color-white">
			<div class="col-8">
				<p>当前选择方案</p>
			</div>
			<div class="col-4 mui-navigate-right font-14 tc-select mui-text-right"><span @click="selectMore()" id="select-more">经济版</span></div>
		</div>
		<!-- 套餐 -->
		<template v-for="(index,tclist) in tcList">
			<ul class="mui-table-view font-14 box box-first" v-if="tclist.selected">
				<div class="mui-table-view-cell">
					<span class="by-item-tit">{{tclist.tcName}}</span>
					<span class="text-label bg-color-green color-white">优惠{{tclist.tcJmfy}}元</span>
					<p class="item-actions mui-pull-right" v-if="!isEdit">
						<i class="mui-icon mui-icon-compose edit" @click="editByitem()"></i>
						<i class="mui-icon mui-icon-trash delete" data-id="tc1" @click="deleteItem('tc',index)"></i>
					</p>
					<p class="item-actions mui-pull-right color-blue save-by-item" v-if="isEdit" @click="saveByItem()">
						保存
					</p>
				</div>
				<template v-for="(index,tcxmlist) in tclist.tcxmList">
				<li class="mui-table-view-cell flex-box by-item" data-id="{{index}}">
					<div class="flex-2">
						<div class="font-deep">{{tcxmlist.xmName}}</div>
						<p class="font-10"> {{tcxmlist.Defaultpj.pjName}} </p>
					</div>
					<div class="flex-1  mui-text-right">
						<div class="item-price" v-if="tcxmlist.Defaultpj.pjPrice">￥{{tcxmlist.Defaultpj.pjPrice}}</div>
						<div class="item-price" v-if="!tcxmlist.Defaultpj.pjPrice">￥{{tcxmlist.xmprice}}</div>
						<p data-id="tc-item-{{index}}">x{{tcxmlist.xmNum}}</p>
					</div>
					<div v-if="tcxmlist.xmName.indexOf('项检测')==-1" class="by-item-actions flex-box" v-show="isEdit">
						<div class="flex-2">
							<div class="mui-numbox mt-numbox" data-numbox-min="1" data-tc-numbox-id="{{index}}">
							  	<!-- "-"按钮，点击可减小当前数值 -->
							 	<button class="mui-btn mui-numbox mt-numbox-btn-minus" type="button" disabled @click="MINUS(index,$event,true)">-</button>
								<input class="mui-numbox-input mt-numbox-input" type="number" value="1" readonly unselectable="on" onfocus="this.blur()"/>
								<!-- "+"按钮，点击可增大当前数值 -->
								<button class="mui-btn mui-numbox mt-numbox-btn-plus" type="button" @click="PLUS(index,$event,true)">+</button>
							</div>
						</div>
						<div class="flex-1" @click="changeParts('tc',index)">
							<div class="font-12">
								<p><i class="mui-icon mui-icon-loop"></i></p>
								<div>更换</div>
							</div>
						</div>
					</div>
				</li>
				</template>
			</ul>
		</template>
		<!-- 非套餐项目 -->
		<template v-for="(index,xmlist) in xmList">
		<ul class="mui-table-view font-14 box box-first" v-show="xmlist.selected">
			<div class="mui-table-view-cell">
				<span class="by-item-tit">
					{{xmlist.xmName}}
				</span>
				<p class="item-actions mui-pull-right" v-show="!xmlist.xmIsEdit">
					<i class="mui-icon mui-icon-compose" @click="xmEdit(index)" v-if="xmListHasParts[index]"></i>
					<i class="mui-icon mui-icon-trash" @click="deleteItem('xm',index)"></i>
				</p>
				<p class="item-actions mui-pull-right color-blue save-xm-item" v-show="xmlist.xmIsEdit" @click="saveXmItem(index)">
					保存
				</p>
			</div>
			<li class="mui-table-view-cell flex-box">
				<div class="flex-2">
					<div class="font-deep">{{xmlist.xmName}}</div>
					<p class="font-10"> {{xmlist.Defaultpj.pjName}} </p>
				</div>
				<div class="flex-1 mui-text-right">
					<div class="item-price" v-if="xmlist.Defaultpj.pjPrice">￥{{xmlist.Defaultpj.pjPrice}}</div>
					<div class="item-price" v-if="!xmlist.Defaultpj.pjPrice">￥{{xmlist.xmprice}}</div>
					<p>x{{xmlist.xmNum}}</p>
				</div>
				<!-- 编辑数量、更换产品 -->
				<div class="by-item-actions flex-box" v-show="xmlist.xmIsEdit" v-if="xmListHasParts[index]">
					<div class="flex-2">
						<div class="mui-numbox mt-numbox" data-numbox-min="1">
						  <!-- "-"按钮，点击可减小当前数值 -->
						 	<button class="mui-btn mui-numbox mt-numbox-btn-minus" type="button" disabled @click="MINUS(index,$event,false)">-</button>
							<input class="mui-numbox-input mt-numbox-input" type="number" value="1" readonly unselectable="on" onfocus="this.blur()"/>
							<!-- "+"按钮，点击可增大当前数值 -->
							<button class="mui-btn mui-numbox mt-numbox-btn-plus" type="button" @click="PLUS(index,$event,false)">+</button>
						</div>
					</div>
					<div class="flex-1" @click="changeParts('xm',index)">
						<div class="font-12">
							<p><i class="mui-icon mui-icon-loop"></i></p>
							<div>更换</div>
						</div>
					</div>
				</div>
			</li>
		</ul>
	</template>
		<!-- 服务费用 -->
		<ul class="mui-table-view font-14 box box-first">
			<div class="mui-table-view-cell">
				<span class="by-item-tit">
					服务费用
				</span>
			</div>
			<li class="mui-table-view-cell flex-box" v-for="item in fwxm">
				<div class="flex-2">
					<p class="font-deep">{{item.xmName}}</p>
				</div>
				<div class="flex-1 mui-text-right">
					<div class="item-price">￥{{item.xmfy}}</div>
				</div>
			</li>
		</ul>
		<!-- 优惠 -->
		<ul class="mui-table-view font-14 box box-first">
			<div class="mui-table-view-cell">
				<span class="by-item-tit">
					优惠
				</span>
				<p class="font-12 fr" v-show="tcList.length>0 && !tcList[0].selected">暂无优惠</p>
			</div>
			<li class="mui-table-view-cell flex-box" v-show="isTCYH">
				<div class="flex-2">
					<p class="font-deep">保养套餐优惠</p>
				</div>
				<div class="flex-1 mui-text-right">
					<p>-￥{{tcList.length>0 && tcList[0].tcJmfy}}</p>
				</div>
			</li>
			<li class="mui-table-view-cell flex-box" v-show="isBZDJM">
				<div class="flex-2">
					<p class="font-deep">选用爱特优选配件优惠</p>
				</div>
				<div class="flex-1 mui-text-right">
					<p>-￥{{fwxmyh}}</p>
				</div>
			</li>
		</ul>
		<!-- 合计 -->
		<div class="bottom-bar bg-color-white ">
			<div class="col-8 total-price"><span>合计：</span><span class="price">￥{{totalPrice}}</span></div>
			<div class="col-4 by-confirm bg-color-blue color-white tc" id="byConfirm" @click="confirmByOrder()">确定</div>
		</div>
		<!-- 输入行驶里程模态框 -->
		<div class="modal-mileage" v-if="isEnterMileage" transition="fade">
			<div class="modal-body">
				<i class="iconfont">&#xe609;</i>
				<input type="tel" id="carMileageInput" maxlength="6"/>
				<span>km</span>
			</div>
			<div class="modal-footer bg-color-blue">
				<div class="modal-mileage-confirm color-white tc" id="modalMileageConfirm" @click="carMileageConfirm">确定</div>
			</div>
		</div>
	</div>
	<!-- 更换配件弹出框 -->
	<div class="parts-type-box" v-if="isChangePart" transition="slideFromBottom">
		<div class="patrs-type-head clearfix">
			<div class="btn-confirm fr font-14" @click="confirmParts()">确定</div>
		</div>
		<ul class="parts-type-list">
			<li v-for="(index,item) in partsList" class="mui-table-view-cell font-14" @click="selectParts(item.isTc,index)">
				<div class="col-5">
					{{item.pjName}}
				</div>
				<div class="col-5 pj-price mui-text-right">
					￥ {{item.pjPrice.toFixed(2)}}
				</div>
				<div class="col-2 mui-text-right color-blue" v-show="item.selected">
					<i class="iconfont font-14">&#xe60f;</i>
				</div>
			</li>
		</ul>
	</div>
</template>
<style type="text/css" scoped>
	.car-info{padding:10px;}
	.car-logo{width:1rem;height:1rem;border-radius:50%;margin-right:10px;background:#eee;}
	.car-logo img{max-width:100%;}
	.car-brand1{margin:0;padding:5px 0;}
	.car-mileage{border-left:1px solid #eee;}
	.car-mileage{font-size:17px;}
	.select-more{padding-right:18px;}
	.select-more a{color:#2f77e3;}
	.tc-select{padding-right:18px;}
	.text-label{padding:3px 8px;border-radius:2px;}
	.item-price{color:#ff8317;font-size:14px;}
	.by-item-tit{font-size:17px;}
	.bottom-bar{height:1rem;position:fixed;bottom:0;left:0;right:0;}
	.by-confirm{line-height:1rem;}
	.total-price{line-height:1rem;padding-left:15px;}
	.modal-mileage{width:80%;height:100px;top:30%;left:10%;right:10%;position:fixed;background:#fff;border-radius:3px;padding-top:25px;z-index:1000;}
	.modal-mileage .modal-body{margin:0 15px 15px 15px;position:relative;}
	.modal-mileage .modal-body i{position:absolute;top:50%;transform:translateY(-50%);left:3px;}
	.modal-mileage .modal-body span{position:absolute;top:50%;transform:translateY(-50%);right:3px;}
	.modal-mileage .modal-body input{border:none;border-bottom:1px solid #e1e1e1;padding-left:25px;border-radius:0;}
	.modal-mileage .modal-footer{line-height:46px;}
	.fade-transition{transition:all .3s ease;opacity:1}
	.fade-enter{opacity:0;}
	.fade-leave{opacity:0;}
	.by-item{position:relative;}
	.by-item-actions{position:absolute;width:70%;background-color:#fff;height:100%;top:0;bottom:0;right:0;}
	.mt-numbox{background-color:#fff;border:1px solid #eee;border-radius:0;height:30px;padding:0 28px 0 28px;width:90px;}
	.mt-numbox .mt-numbox-btn-minus,.mt-numbox .mt-numbox-btn-plus{background-color:#fff;width:28px;border-radius:0;}
	.mt-numbox .mt-numbox-input{border-left:1px solid #eee!important;border-right:1px solid #eee!important;}
	.mt-numbox-btn-minus{left:0;}
	.mt-numbox-btn-plus{right:0;}
	.by-item-actions [class^=flex-]{justify-content:center;align-items:center;display:flex;}
	.save-by-item{line-height:22px;}
	.save-xm-item{line-height:22px;}
	.patrs-type-head{padding:10px;border-bottom:1px solid #eee;border-top:1px solid #e1e1e1;}
	.parts-type-box{width:100%;height:40%;background:#fff;position:fixed;bottom:0;z-index:1000;}
	.patrs-type-head>.btn-confirm{color:#2f77e3;}
	.slideFromBottom-transition{transition:all .4s ease;transform:translateY(0);}
	.slideFromBottom-enter,.slideFromBottom-leave{transform:translateY(100%);}
	.pj-price{color:#ff8317;}
	.parts-type-list{height:calc(100% - 43px);overflow:auto;}

</style>
<script type="ecmascript-6">
	import datePicker from '../../components/date-picker/date-picker.vue'
	import picker from '../../components/picker/picker.vue'
	import Page from '../../base/Page'
	import apiurl from '../../config/apiurl'
    import { API } from '../../config/constants'
	export default new Page({
		vuex:{
			actions:{
				selectMaintenanceItem:function({dispatch},data){
                    dispatch('UPD_MAINTENANCE_ITEM',data);
                },
				updMaintenanceItemNum:function({dispatch},data){
					dispatch('UPD_MAINTENANCE_ITEM_NUM',data);
				},
				updMaintenanceOrderTotalPrice:function({dispatch},data){
					dispatch('UPD_MAINTENANCE_ORDER_TOTAL_PRICE',data);
				},
				updMaintenanceOrderPlanType:function({dispatch},data){
					dispatch('UPD_MAINTENANCE_ORDER_PLANTYPE',data);
				},
				updMaintenanceDiscount:function({dispatch},data){
					dispatch('UPD_MAINTENANCE_DISCOUNT',data);
				},
				updCarmileage:function({dispatch},data){
					dispatch('UPD_CARMILEAGE',data);
				}
			},
			getters:{
				carBrand:function(state){
					return state.mycar.carBrand
				},
				carModel:function(state){
					return state.mycar.carModel
				},
				carBuyDate:function(state){
					return state.mycar.carBuyDate
				},
				carBrandImage:function(state){
					return state.mycar.carBrandImage
				},
				carMileage:function(state){
					return state.carMileage
				},
				getMaintenanceItemNum:function(state){
					return state.maintenanceOrder.byItemNum
				},
				getTcList:function(state){
					return state.maintenanceOrder.byItem.tcList
				},
				getXmList:function(state){
					return state.maintenanceOrder.byItem.xmList
				}
			}
		},
		data(){
			return{
				isEnterMileage:false,
				isChangePart:false,
				isEdit:false,
				itemNum:0,
				tcprice:'',
				mask:'',
				tcRank:[
					{value:'1',text:'经济版'},
					{value:'2',text:'普通版'},
					{value:'3',text:'豪华版'}
				],
				partsList:[],
				fwxm:[],
				fwxmyh:0,
				preferential:[],
				tcList:[],
				xmList:[],
				pjList:[],
				byItem:{tcList:{},xmList:{}},
				scrollTop:'',
				xmIndex:'',
				planType:'经济版',
				planTYPE:3,
				tcListIsZdArr:[],
				xmListIsZdArr:[],
				xmListHasParts:[]
			}
		},
		created(){
			let that = this;

		},
		components:{
			datePicker,
			picker
		},
		ready(){
			let that = this;
			let zdText = '自带配件';
			mui('.mt-numbox').numbox();
			if(that.tcList.length<=0){
				that.getAllItems(3);
			}
			console.log(that.carMileage);
			//获取服务项目费用
			this.getJSON(API.GET_SERVICE_ITEMS,{},res=>{
				that.fwxm = res.resultData;
				that.fwxmyh = 0;
				that.fwxm.forEach(function(item){
					that.fwxmyh += parseFloat(item.xmfy);
				})
			});
			//判断是否有优惠
			if(that.tcList.length>0 && that.tcList[0].selected){
				that.isTCYH = true;
				if(that.tcList[0].isBzdjm==0){
					that.isBZDJM = true;
				}else{
					that.isBZDJM = false;
				}
			}else{
				that.isTCYH = false;
				that.isBZDJM = false;
			}
		},
		computed:{
			isTCYH:function(){
				if(this.tcList.length>0){
					if(this.tcList[0].selected){
						return true
					}else{
						return false
					}
				}
			},
			isBZDJM:function(){
				if(this.tcList.length>0 && this.tcList[0].selected && this.tcList[0].isBzdjm==0){
					return true
				}else{
					return false
				}
			},
			totalPrice:function(){
				let that = this;
				let total = 0;
				//套餐价格
				if(this.tcList.length>0 && this.tcList[0].selected){
					this.tcList[0].tcxmList.forEach(function(item){
						if(item.Defaultpj.pjPrice==null){
							total +=  item.xmprice
						}else{
							total +=  item.xmprice + item.Defaultpj.pjPrice * item.xmNum;
						}
					})
				}
				this.tcprice =total;
				//项目价格
				this.xmList.length>0 && this.xmList.forEach(function(item){
					if(item.selected){
						if(item.Defaultpj.pjPrice){
							total += item.xmprice + item.xmNum * item.Defaultpj.pjPrice;
						}else{
							total += item.xmprice;
						}
					}
				});
				//工时费用
				this.fwxm.forEach(function(item){
					total += parseFloat(item.xmfy);
				})
				//如果有优惠，减去优惠费用
				if(this.tcList.length>0 && this.tcList[0].selected){
					total -= parseFloat(this.tcList[0].tcJmfy);
				}
				if(this.tcList.length>0 && this.tcList[0].selected && this.tcList[0].isBzdjm==0){
					total -= parseFloat(this.fwxmyh);
				}
				return total.toFixed(2)
			}
		},
		methods:{
			countItemNum:function(){
				let that = this;
				that.itemNum = 0;
				that.tcList.forEach(function(item){
					item.selected && that.itemNum++
				});
				that.xmList.forEach(function(item){
					item.selected && that.itemNum++;
				});
			},
			//选择方案
			selectMore:function(){
				let that = this;
                (function($, doc) {
                    $.init();
                    $.ready(function() {
                        //普通示例
                        var picker = new $.PopPicker();
                        picker.setData(that.tcRank);
						picker.pickers[0].setSelectedValue('1', 0);
                        var tc=doc.getElementById('select-more');
                        picker.show(function(items) {
                            tc.innerText = items[0].text;
							if(items[0].text.indexOf('经济')!=-1){
								that.getAllItems(3);
								that.planType = '经济版';
							}else if(items[0].text.indexOf('普通')!=-1){
								that.getAllItems(2);
								that.planType = '普通版';
							}else{
								that.getAllItems(1);
								that.planType = '豪华版';
							}
                            //set to data param
                        }, false);
                    });
                })(mui, document);
			},
			getAllItems:function(planType){
				let from = this.$route.params.from;
				let that = this;
				let zdText = '自带配件';


				//获取所有
				that.getJSON(API.GET_ALL_ITEMS,{planType:planType},res=>{
					that.pjList = res.resultData.pjList;
					//初始化套餐和单独项目的isZd
					that.tcListIsZdArr = [];
					that.xmListIsZdArr = [];
					res.resultData.tcList[0].tcxmList.forEach(function(item,index){
						that.tcListIsZdArr.push(item.isZd);
						item.isZd = 1;
					})
					res.resultData.xmList.forEach(function(item,index){
						that.xmListIsZdArr.push(item.isZd);
						var flag = false;
						that.pjList.forEach(function(pjItem){
							if(pjItem.pjlb.indexOf(item.pjlb)!=-1){
								flag = true;
								return
							}
						})
						that.xmListHasParts.push(flag);
						item.isZd = 1;
					});

					if(that.planTYPE && that.planTYPE == planType){
						if(that.tcList.length > 0 || that.xmList.length > 0){
							that.planTYPE = planType;
							console.log(1)
							return
						}else{
							that.tcList = [];
							that.xmList = [];
							console.log(2);
							//判断入口
							if(from == 'BY'){
								res.resultData.tcList[0].selected = true;
								that.tcList.push(res.resultData.tcList[0]);
								that.tcList[0].tcxmList.forEach(function(item){
								})
								for(let i = 0;i < res.resultData.xmList.length;i++){
									res.resultData.xmList[i].selected = false;
									that.xmList.push(res.resultData.xmList[i]);
									that.$set('xmList['+i+'].xmIsEdit',false);
								}
								that.countItemNum();
							}else if(from == 'KQLX'){
								res.resultData.tcList[0].selected = false;
								that.tcList.push(res.resultData.tcList[0]);
								for(let i = 0;i < res.resultData.xmList.length;i++){
									that.xmList.push(res.resultData.xmList[i]);
									that.$set('xmList['+i+'].xmIsEdit',false);
									if(res.resultData.xmList[i].xmName.indexOf('空气滤芯')!=-1){
										that.xmList[i].selected = true;
									}

								}
								that.countItemNum();

							}else if(from == 'KTLX'){
								res.resultData.tcList[0].selected = false;
								that.tcList.push(res.resultData.tcList[0]);
								for(let i = 0;i < res.resultData.xmList.length;i++){
									that.xmList.push(res.resultData.xmList[i]);
									that.$set('xmList['+i+'].xmIsEdit',false);
									if(res.resultData.xmList[i].xmName.indexOf('空调滤芯')!=-1){
										that.xmList[i].selected = true;
									}

								}
								that.countItemNum();
							}else if(from =='moreItems'){
								if(that.getTcList){
									that.tcList.push(that.getTcList[0]);

									that.itemNum = that.getMaintenanceItemNum;
								}
								if(that.getXmList){
									let tmpxmList = res.resultData.xmList;
									that.getXmList.forEach(function(item,index){
										if(item.selected){
											tmpxmList[index].selected = true;
										}
									})
									that.xmList = tmpxmList;
									for(let i = 0;i<that.xmList.length;i++){
										that.$set('xmList['+i+'].xmIsEdit',false);
									}
									that.itemNum = that.getMaintenanceItemNum;
								}
							}
							that.planTYPE = planType;
						}
						that.planTYPE = planType;
					}else{
						that.tcList = [];
						that.xmList = [];
						console.log(3);
						//判断入口
						if(from == 'BY'){
							res.resultData.tcList[0].selected = true;
							that.tcList.push(res.resultData.tcList[0]);

							for(let i = 0;i < res.resultData.xmList.length;i++){
								res.resultData.xmList[i].selected = false;
								that.xmList.push(res.resultData.xmList[i]);
								that.$set('xmList['+i+'].xmIsEdit',false);

							}
							that.countItemNum();
						}else if(from == 'KQLX'){
							res.resultData.tcList[0].selected = false;
							that.tcList.push(res.resultData.tcList[0]);
							for(let i = 0;i < res.resultData.xmList.length;i++){
								that.xmList.push(res.resultData.xmList[i]);
								that.$set('xmList['+i+'].xmIsEdit',false);
								if(res.resultData.xmList[i].xmName.indexOf('空气滤芯')!=-1){
									that.xmList[i].selected = true;
								}

							}
							that.countItemNum();

						}else if(from == 'KTLX'){
							res.resultData.tcList[0].selected = false;
							that.tcList.push(res.resultData.tcList[0]);
							for(let i = 0;i < res.resultData.xmList.length;i++){
								that.xmList.push(res.resultData.xmList[i]);
								that.$set('xmList['+i+'].xmIsEdit',false);
								if(res.resultData.xmList[i].xmName.indexOf('空调滤芯')!=-1){
									that.xmList[i].selected = true;
								}

							}
							that.countItemNum();
						}else if(from =='moreItems'){
							if(that.getTcList){
								res.resultData.tcList[0].selected = true;
								that.tcList.push(res.resultData.tcList[0]);

								that.itemNum = that.getMaintenanceItemNum;
							}
							if(that.getXmList){
								let tmpxmList = res.resultData.xmList;
								that.getXmList.forEach(function(item,index){
									if(item.selected){
										tmpxmList[index].selected = true;
									}
								})
								that.xmList = tmpxmList;
								for(let i = 0;i<that.xmList.length;i++){
									that.$set('xmList['+i+'].xmIsEdit',false);

								}
								that.itemNum = that.getMaintenanceItemNum;
							}
							that.itemNum = that.getMaintenanceItemNum;
						}
						that.planTYPE = planType;
					}
				})

			},
			//输入行驶里程
			enterMileage:function(){
				let that = this;
				let timer = null;
				var mask = mui.createMask(
					function(){
						that.isEnterMileage = false;
						}
					);
				that.mask = [];
				that.mask = mask;
				this.isEnterMileage = !this.isEnterMileage;
				mask.show();
				timer = setTimeout(function(){
					document.getElementById('carMileageInput').focus();
				},300);

			},
			//确认行驶里程
			carMileageConfirm:function(ev){
				let that = this;
				let value = document.getElementById('carMileageInput').value;
				value = value.replace(/\s+/g,'');
				that.isEnterMileage = false;
				this.mask.close();
				//如果不是纯数字
				if(/\D+/g.test(value)){
					mui.toast('请输入数字',{ duration:'long', type:'div' });
					value = '';
					return
				};
				//如果不是有效数字
				if(/^00*0$/.test(value)){
					mui.toast('请输入有效数字',{ duration:'long', type:'div' });
					value = '';
					return
				}
				that.updCarmileage(Math.ceil(value));
				//console.log(111);
				//that.carMileage = Math.ceil(value);

			},
			//编辑套餐
			editByitem:function(){
				this.isEdit = !this.isEdit;
				mui('.mt-numbox').numbox();

			},
			//保存套餐
			saveByItem:function(){
				this.isEdit = !this.isEdit;
			},
			//取得套餐各个项目中配件的个数、取得非套餐项目中配件个数
			getValue:function(index,ev,isTc){
				var el = ev.currentTarget;
				if(isTc){
					console.log(this.tcList[0].tcxmList[index]);
					this.tcList[0].tcxmList[index].xmNum = mui(el).numbox().getValue();
				}else{
					this.xmList[index].xmNum = mui(el).numbox().getValue();
				}
			},
			PLUS(index,ev,isTc){
				var el = ev.currentTarget.previousElementSibling;
				if(isTc){
					el.value = this.tcList[0].tcxmList[index].xmNum;
					el.value++;
					if(el.value > 1){
						el.previousElementSibling.removeAttribute('disabled');
					}
					this.tcList[0].tcxmList[index].xmNum = el.value;
				}else{
					el.value = this.xmList[index].xmNum;
					el.value++;
					if(el.value > 1){
						el.previousElementSibling.removeAttribute('disabled');
					}
					this.xmList[index].xmNum = el.value;
				}
			},
			MINUS(index,ev,isTc){
				if(ev.currentTarget.getAttribute('disabled')){
					return
				}
				var el = ev.currentTarget.nextElementSibling;
				if(isTc){
					el.value = this.tcList[0].tcxmList[index].xmNum;
					el.value--;
					if(el.value <= 1){
						el.previousElementSibling.setAttribute('disabled',true);
					}
					this.tcList[0].tcxmList[index].xmNum = el.value;
				}else{
					el.value = this.xmList[index].xmNum;
					el.value--;
					if(el.value <= 1){
						el.previousElementSibling.setAttribute('disabled',true);
					}
					this.xmList[index].xmNum = el.value;
				}
			},
			//非套餐项目编辑
			xmEdit:function(index){
				console.log(this.xmList[index]);
				this.xmList[index].xmIsEdit = !this.xmList[index].xmIsEdit;
				mui('.mt-numbox').numbox();
			},
			//非套餐项目保存
			saveXmItem:function(index){
				this.xmList[index].xmIsEdit = !this.xmList[index].xmIsEdit;
				mui('.mt-numbox').numbox();
			},
			//删除项目
			deleteItem:function(from,i){
				let that = this;
				if(from=='tc'){
					mui.confirm('确认删除此项目吗','提示',['否','是'],function(e){
						if(e.index==0){
							return
						}else if(e.index==1){
							that.tcList[i].selected = false;
							that.itemNum--;
							that.updMaintenanceItemNum(that.itemNum);
							return
						}
					})

				}else if(from == 'xm'){
					mui.confirm('确认删除此项目吗','提示',['否','是'],function(e){
						if(e.index==0){
							return
						}else if(e.index==1){
							that.xmList[i].selected = false;
							that.byItem.tcList = that.tcList;
							that.byItem.xmList = that.xmList;
							that.selectMaintenanceItem(that.byItem);
							that.itemNum--;
							that.updMaintenanceItemNum(that.itemNum);
							return
						}
					})
				}
			},
			byItemSave:function(){
				let that = this;
				that.byItem.tcList = that.tcList;
				that.byItem.xmList = that.xmList;
				that.selectMaintenanceItem(that.byItem);
				that.updMaintenanceItemNum(that.itemNum);
				that.$route.router.go('/maintenance/maintenanceItems');
			},
			//更换配件
			changeParts:function(from,index){
				let that = this;
				let scrollTop = document.body.scrollTop;
				that.scrollTop = scrollTop;
				that.xmIndex = index;
				//固定body
				document.getElementsByTagName('body')[0].style.cssText = 'position:absolute;width:100%;z-index:-1;'+'top:'+(-scrollTop)+'px';
				var mask = mui.createMask(function(){
					that.isChangePart = false;
					//释放body
					document.getElementsByTagName('body')[0].style.cssText = 'position:static;width:100%;z-index:-1;';
					document.body.scrollTop = that.scrollTop;
				});
				mask.show();
				that.mask = mask;
				that.isChangePart = true;
				var zdItem = {
					"pjCode":"",
					"pjpp":"",
					"pjlb":"",
					"pjName":"自带配件",
					"selected":false,
					"pjPrice":0,
					"isTc":false
				}
				//更换套餐配件
				if(from == 'tc'){
					let partsType = that.tcList[0].tcxmList[index].pjlb;
					that.partsList = [];
					that.pjList.forEach(function(item,index){
						if(item.pjlb == partsType){
							that.$set('pjList['+index+'].isTc',true);
							that.partsList.push(item);
						}
					});
					if(that.tcListIsZdArr[index] ==0){
						zdItem.isTc = true;
						zdItem.pjlb = partsType;
						that.partsList.push(zdItem);
					}
				}else{//更换项目配件
					let partsType = that.xmList[index].pjlb;
					that.partsList = [];
					that.pjList.forEach(function(item){
						if(item.pjlb == partsType){
							that.$set('pjList['+index+'].isTc',false);
							that.partsList.push(item);
						}
					})
					if(that.xmListIsZdArr[index] ==0){
						zdItem.pjlb = partsType;
						that.partsList.push(zdItem);
					}
				}
			},
			//选择配件
			selectParts:function(isTc,index){
				let that = this;
				if(isTc){	//选择套餐配件
					that.partsList.forEach(function(item){
						item.selected = false;
					})
					that.partsList[index].selected = true;
					if(that.partsList[index].pjName.indexOf('自带')!=-1){
						that.tcList[0].isBzdjm = 1;
						that.tcList[0].tcxmList[that.xmIndex].isZd = 0;
					}else{
						that.tcList[0].isBzdjm = 0;
						that.tcList[0].tcxmList[that.xmIndex].isZd = 1;
					}
					let partsType = that.partsList[index].pjlb;
					that.tcList[0].tcxmList.forEach(function(item){
						if(item.pjlb==partsType){
							item.Defaultpj = that.partsList[index];
						}
					})
				}else{		//选择项目配件
					that.partsList.forEach(function(item){
						item.selected = false;
					})
					that.partsList[index].selected = true;
					if(that.partsList[index].pjName.indexOf('自带')!=-1){
						that.xmList[that.xmIndex].isZd = 0;
					}else{
						that.xmList[that.xmIndex].isZd = 1;
					}
					let partsType = that.partsList[index].pjlb;
					if(that.xmList[that.xmIndex].pjlb == partsType){
						that.xmList[that.xmIndex].Defaultpj = that.partsList[index];
					}
				}
			},
			//确认配件
			confirmParts:function(){
				let that = this;
				that.mask.close();
				that.isChangePart = false;
				that.partsList = [];
				that.xmIndex = '';
				//释放body
				document.getElementsByTagName('body')[0].style.cssText = 'position:static;width:100%;z-index:-1;';
				document.body.scrollTop = that.scrollTop;
			},
			//确定订单
			confirmByOrder:function(){
				let that = this;
				let discount = {tcjm:0,fzdjm:0}
				if(this.carBrand =='' ||this.carBuyDate==''||this.carBrand ==null ||this.carBuyDate==null){
					mui.toast('请完善车辆信息',{ duration:'short', type:'div' });
                        return;
				}
				that.tcList[0].tcPrice = that.tcprice - that.tcList[0].tcJmfy;
				that.byItem.tcList = that.tcList;
				that.byItem.xmList = that.xmList;
				if(!that.tcList[0].selected){
					var nothingSelected = true;
					that.xmList.forEach(function(item){
						if(item.selected){
							nothingSelected = false;
							return
						}
					})
					if(nothingSelected){
						mui.toast('请至少选择1个项目',{ duration:'short', type:'div' })
						return
					}
				}
				that.updMaintenanceOrderTotalPrice(that.totalPrice);
				that.selectMaintenanceItem(that.byItem);
				that.updMaintenanceItemNum(that.itemNum);
				that.updMaintenanceOrderPlanType(this.planType);
				if(that.tcList[0].selected){
					discount.tcjm = that.tcList[0].tcJmfy
				}
				if(that.tcList[0].selected && that.tcList[0].isBzdjm==0){
					discount.fzdjm = that.fwxmyh;
				}
				that.updMaintenanceDiscount(discount);
				that.post(API.POST_UPDATEMILEAGE, {
                        carMileage:that.carMileage?that.carMileage:0
                        }, res => {
                        console.log(res);
                    });
				that.$route.router.go('/maintenance/maintenanceOrderConfirm');
			}
		}
	})
</script>
